package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	accessToken := "80_0vvhq6vBk-r0_d9Bp1TRbFB-Eei8j0SMN-qzbjaA7SYRu2NONgubKP8KvuGZ6DDQMcEGe2xh1axavUl-2iTKJRw9kuUHBJa2LuZAR-Sgep-KThHu77mpuYM2r0IQVAiAEALQV"
	url := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/draft/add?access_token=%s", accessToken)

	// 创建请求体
	requestBody := map[string]interface{}{
		"articles": []map[string]interface{}{
			{
				"title":               "测试标题",
				"author":              "慕溪code",
				"digest":              "摘要信息",
				"content":             "测试接口图文内容",
				//"content_source_url":  "图文消息的原文地址（非必填）",
				"thumb_media_id":      "EdiS0wbrTMmoD_ZQZOruhNLjw4s6gwGAAMPBrbidqm1Ob8DqoK-3DC6O0cKw5ara",  //"图文消息的封面图片素材id（必须是永久MediaID）必填",
				"need_open_comment":   1,// 0 关闭评论， 1 打开评论
				"only_fans_can_comment": 0, // 0所有人可评论(默认)，1粉丝才可评论
				//"pic_crop_235_1":      "X1_Y1_X2_Y2", 封面裁剪非必填
				//"pic_crop_1_1":        "X1_Y1_X2_Y2",
			},
		},
	}

	// 将请求体编码为JSON
	jsonData, err := json.Marshal(requestBody)
	if err != nil {
		fmt.Println("Error marshaling JSON:", err)
		return
	}

	// 创建POST请求
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	// 设置请求头
	req.Header.Set("Content-Type", "application/json")

	// 发送请求
	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Error sending request:", err)
		return
	}
	defer resp.Body.Close()

	// 读取响应
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response:", err)
		return
	}

	// 打印响应
	fmt.Println("Response Status:", resp.Status)
	fmt.Println("Response Body:", string(body))
}
